/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itsc.ds2.model;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Eli
 */
@Entity
@Table(name = "musicalgenres")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "MusicalGenres.findAll", query = "SELECT m FROM MusicalGenres m"),
    @NamedQuery(name = "MusicalGenres.findByIdgenre", query = "SELECT m FROM MusicalGenres m WHERE m.idgenre = :idgenre"),
    @NamedQuery(name = "MusicalGenres.findByName", query = "SELECT m FROM MusicalGenres m WHERE m.name = :name")})
public class MusicalGenres implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idgenre")
    private Integer idgenre;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "name")
    private String name;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idgenre")
    private Collection<Discs> discsCollection;

    public MusicalGenres() {
    }

    public MusicalGenres(Integer idgenre) {
        this.idgenre = idgenre;
    }

    public MusicalGenres(Integer idgenre, String name) {
        this.idgenre = idgenre;
        this.name = name;
    }

    public Integer getIdgenre() {
        return idgenre;
    }

    public void setIdgenre(Integer idgenre) {
        this.idgenre = idgenre;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlTransient
    public Collection<Discs> getDiscsCollection() {
        return discsCollection;
    }

    public void setDiscsCollection(Collection<Discs> discsCollection) {
        this.discsCollection = discsCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idgenre != null ? idgenre.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MusicalGenres)) {
            return false;
        }
        MusicalGenres other = (MusicalGenres) object;
        if ((this.idgenre == null && other.idgenre != null) || (this.idgenre != null && !this.idgenre.equals(other.idgenre))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return  name;
    }
    
}
